{"componentChunkName":"component---src-templates-blog-template-js","path":"/blog/refactoring-legacy-code-a-case-study","result":{"data":{"markdownRemark":{"html":"<p>Often refactoring examples are fairly straightforward, leaving you wondering what to do with the difficult cases of legacy code.</p>\n<p>This process took me some ten commits and a couple of hours but it's worth looking at the steps to see a more complex example.</p>\n<h4>Starting point</h4>\n<p>We have a legacy class which downloads a file from Sharepoint.</p>\n<p>There are no tests which is something I wanted to remedy. To do that we need to add interfaces around the Sharepoint objects as they are near-enough impossible to mock having constructors which take Sharepoint context objects with constructors like:</p>\n<pre><code>    public Folder(ClientRuntimeContext context, ObjectPath objectPath);\n</code></pre>\n<p>where ClientRuntimeContext is :</p>\n<pre><code>    protected ClientRuntimeContext(string webFullUrl);\n</code></pre>\n<p>and so on, which means that the only (or at least <em>one</em>) sensible option is to wrap this class (in fact a number of classes) in <a href=\"https://en.wikipedia.org/wiki/Adapter_pattern\" target=\"_blank\" rel=\"noopener noreferrer\">Adapter pattern</a> implementations.</p>\n<p>In full, the starting point for this exercise:</p>\n<pre><code>    private static void DownloadFile(ClientContext clientContext, File file, string fileName)\n    {\n      var maxAttempts = 10;\n      for (var attemptNumber = 1; attemptNumber &#x3C; maxAttempts + 1; attemptNumber++)\n      {\n        try\n        {\n          using (var fileStream = System.IO.File.Create(fileName))\n          {\n            clientContext.Load(file);\n            var stream = file.OpenBinaryStream();\n\n            clientContext.ExecuteQueryAsync().Wait();\n\n            stream.Value.CopyTo(fileStream);\n          }\n\n          attemptNumber = maxAttempts + 1;\n\n        }\n        catch (AggregateException ex) when (ex.Message.Contains(\"(503) Service Unavailable\"))\n        {\n          OutputWriter.Write(\n            $\"   >> Getting file {fileName}: 503 returned. Waiting before call number {attemptNumber + 1} of {maxAttempts} attempts.\");\n          Thread.Sleep(350 + 200 * attemptNumber);\n        }\n      }\n    }\n</code></pre>\n<p>OK, so here is what I did, with at each step the commit message I used.</p>\n<h4>Commit 1 : Using R# refactored the to-be-wrapped code into a new method</h4>\n<p>Using Resharper I extracted out one of the method calls that use an object that I will need to mock to add some tests. Purely using Resharper here, as I do at almost every stage until I am able to write some tests.</p>\n<p><a href=\"../images/refSp_c1.png\"><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 27.027027027027025%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAFCAYAAABFA8wzAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAA10lEQVQY012QV27EMAxEff9bprhEa68lWb1NSCbGAvvxMGIBNeRUSkFvTYghIDgnmmNEIjg/ekfOGb03NIpDDPDBC/xOOVGto4+OqVBjTZSgwWbfoeYZh1Jw2qDSwMaDqJaop7SC2iuOc8emVqw/C576QKlZ8rUXTLVWmT7GwABe3DErwX3s7u4VR29wfpIVaEXvvWi4lYj/yu6cd1B2w7x/4vvxgeX4wqYXQZlVas/w+HPId3TXBa01jLGw1sLRLfmz2xXfMOYAfWlZ+bSnvC9vZdXSsvALbDCE1VxLYQ8AAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"refSp c1\"\n        title=\"refSp c1\"\n        src=\"/static/f32ee63f1351329e6760e3807320e743/fcda8/refSp_c1.png\"\n        srcset=\"/static/f32ee63f1351329e6760e3807320e743/12f09/refSp_c1.png 148w,\n/static/f32ee63f1351329e6760e3807320e743/e4a3f/refSp_c1.png 295w,\n/static/f32ee63f1351329e6760e3807320e743/fcda8/refSp_c1.png 590w,\n/static/f32ee63f1351329e6760e3807320e743/efc66/refSp_c1.png 885w,\n/static/f32ee63f1351329e6760e3807320e743/c83ae/refSp_c1.png 1180w,\n/static/f32ee63f1351329e6760e3807320e743/5faa8/refSp_c1.png 1444w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></a></p>\n<h4>Commit 2 : Added an interface for the refactored method and a wrapper class to apply the Adapter pattern to (but not used yet)</h4>\n<p>I added a class which implements <a href=\"https://en.wikipedia.org/wiki/Adapter_pattern\" target=\"_blank\" rel=\"noopener noreferrer\">the Adapter pattern</a> to wrap the problematic ClientContext. I then extracted an interface for it so that I can mock it later on.</p>\n<p>I also moved the call to LoadSharepointFile as it does not use the <strong>fileStream</strong> object so does not need to be in the <strong>using</strong> statement.</p>\n<p><a href=\"../images/refSp_c2anon.png\"><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 41.21621621621622%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAICAYAAAD5nd/tAAAACXBIWXMAAA7DAAAOwwHHb6hkAAABDUlEQVQoz5WQC2/CMAyE+///ItrGWNdSYEDe79xsDyq0SUiL9MkXp77kOpRScFgWKKXAurX2h947UkoYpxGnryNijqi9orQi1AcGGaIBHuLV79C+PVBrpYGKXDLpIpppva2aGXJOKHR79B5Wa8EZI/ua842CGANyTXDeQmlFXGGsgY+e+nmFDDMaRWVTdbngej7DKC1GnV7VCK78OzgEJ/KOLjcWwQc6b9K/M3CUTB9LpF+UG6xjinDRwgYjNWSPkPxPfUAMnXNP8RTfOI3xtMV2eRE+SM/XEXv1ubLo6X+G03mH13mDl2mD3fFNDA9mFo52L1UMeeAZIQRYZ7CoiV75vjJfyFDP1J9vdcI3BfFsWlzR/aAAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"refSp c2anon\"\n        title=\"refSp c2anon\"\n        src=\"/static/dec421f654d6c367861b12a4fca90421/fcda8/refSp_c2anon.png\"\n        srcset=\"/static/dec421f654d6c367861b12a4fca90421/12f09/refSp_c2anon.png 148w,\n/static/dec421f654d6c367861b12a4fca90421/e4a3f/refSp_c2anon.png 295w,\n/static/dec421f654d6c367861b12a4fca90421/fcda8/refSp_c2anon.png 590w,\n/static/dec421f654d6c367861b12a4fca90421/efc66/refSp_c2anon.png 885w,\n/static/dec421f654d6c367861b12a4fca90421/c83ae/refSp_c2anon.png 1180w,\n/static/dec421f654d6c367861b12a4fca90421/2fb2d/refSp_c2anon.png 1695w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></a></p>\n<h4>Commit 3 : Wrap the concrete Sharepoint object in the new adapter</h4>\n<p>I use the new ClientContextWrapper (adapter) to wrap the clientContext and then update LoadSharepointFile to accept an object which implements the new IClientContext interface I added in the last commit.</p>\n<p>Ideally the tests would come first, to protect the refactoring. In reality the code cannot easily support this, which is why I had to follow this process. However I can test empirically that the code is not being broken by these changes as I can run the application to assert that the files are still being downloaded as ever they were.</p>\n<p>That's not ideal, I agree, but to get the code into a testable state so that it is protected from changes sometimes you need to be pragmatic about how you get it there.</p>\n<p><a href=\"../images/refSp_c3.png\"><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 28.37837837837838%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAYAAADDl76dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA/ElEQVQY0z1RCZLDIAzL/5/abhJugzm0MmnLjEaGGGEpR+8dpRSknJEJqzdEfnVrDX2wrxac94nbXQ/8vTmkgFQSMnEME6RQ8B6VItUEakVX3Xtj69GuFNWfQBEOUDKk8o7WzWMOCvJ1Q3QO/rrg3m/E20FSQqfwoqCSm7JvdV4scMHh8hdx0lncZ312QnEsPGuuBR0DzaYhT559v405Mcfc9ZqLEw9Ozr6mz/m3keuoMaJwunzfm4XWxTjQFmtlHErr0gS5JiRJH46I4gnLL+597YKjMbNwMujXi3b/kCiSKGgiFsW0H/KxXGpGzIEZ+g0f/RZTZquj7Yz/Ac5v0o4DWaPTAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"refSp c3\"\n        title=\"refSp c3\"\n        src=\"/static/1d4e87109d817c72aaf88b5a3bc610ac/fcda8/refSp_c3.png\"\n        srcset=\"/static/1d4e87109d817c72aaf88b5a3bc610ac/12f09/refSp_c3.png 148w,\n/static/1d4e87109d817c72aaf88b5a3bc610ac/e4a3f/refSp_c3.png 295w,\n/static/1d4e87109d817c72aaf88b5a3bc610ac/fcda8/refSp_c3.png 590w,\n/static/1d4e87109d817c72aaf88b5a3bc610ac/efc66/refSp_c3.png 885w,\n/static/1d4e87109d817c72aaf88b5a3bc610ac/c83ae/refSp_c3.png 1180w,\n/static/1d4e87109d817c72aaf88b5a3bc610ac/d73a9/refSp_c3.png 1591w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></a></p>\n<h4>Commit 4 : Remove the redundant method and call the interface method</h4>\n<p>Now I call the method on the extracted interface (implemented through the new ClientContextWrapper).</p>\n<p><a href=\"../images/refSp_c4.png\"><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 28.37837837837838%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAYAAADDl76dAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAA7ElEQVQY042QWXLEIAxEuf814208eDIGhAGBOxIuZ/kLVa+0ICTUpjKjCfk4UJSUwErOqKVA78/WkCRXW+2knJCLksGVe45r6b5haXLKw/B+Yx0GPKcRj48BdllA+44UApo0P2JEZhnSGC44zOuE5bnAbhbv/ROeHGIimBP/O1wrIMXn+feFxr9zJjsH2jbE1wtkLYKg8Tf2ulMpimxS5Lfd3ogkzD+xiesKL6v6cew49QW1YZpA89xRXVVH7/1F8HDyGfXVEhEOkc80ETzL1CBauf0qiBR7rHf30em6mtpAAd75XhNFW212134BT1jSPHP+w2sAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"refSp c4\"\n        title=\"refSp c4\"\n        src=\"/static/92cfa0c034024b870abeae957c2b7456/fcda8/refSp_c4.png\"\n        srcset=\"/static/92cfa0c034024b870abeae957c2b7456/12f09/refSp_c4.png 148w,\n/static/92cfa0c034024b870abeae957c2b7456/e4a3f/refSp_c4.png 295w,\n/static/92cfa0c034024b870abeae957c2b7456/fcda8/refSp_c4.png 590w,\n/static/92cfa0c034024b870abeae957c2b7456/efc66/refSp_c4.png 885w,\n/static/92cfa0c034024b870abeae957c2b7456/c83ae/refSp_c4.png 1180w,\n/static/92cfa0c034024b870abeae957c2b7456/2cefc/refSp_c4.png 1400w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></a></p>\n<h4>Commit 5 : Add a second method to the interface and move the wrapper creation up so that the method to be tested does not rely on the concrete Sharepoint type</h4>\n<p>DownloadFile method is now accepting an IClientContext, taking it closer to being testable.</p>\n<p><a href=\"../images/refSp_c5.png\"><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 47.972972972972975%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAA7DAAAOwwHHb6hkAAABhklEQVQoz2WSh3KEMBBD+f/vzF0gNPduFK2PZFKGebM2YFleeXqfZzjv0a8L142Me+8DmZdS8PZ4w3N+IuWILs8lNLRefzHFEKCVgjUGgcKJ81YremvodxXBmCK00TjUAWM1TViE6FFbGUL1S7DFCE9Bs20IFDX7jmQtekqQb51kjkvPCMlj2Rcsx4z1/MC8zQjZj2+5pcFUckbigsSF6V4sNd7jIUaHtVUel/P7f3mXi4zjcC/vhelcuOPjgZ293J5PnOsKTbdRa1S2oAgUkEXrtuLUJzl4fAVFNI8f2ddc89hgqvxZUcBqhegcIgUad7+kf0SquGy9wQULRUHnHfsXhuPGYF7hvJhSTDB04ykWGIgcRUKpZITDpOWdpGusGc5EUByXWkYoUl8pU9DTkVwbqaM3VXpDchmicm2k+uBwqhPWvdLNJX0znFJQnE4iIs4EGTdek79Is2Pm9XIayvJGsKZCh03SvalpMMU70S9G4j8QMc8j7vYD7/tjsJoFKuxQ8fjHJx5eCURlJZtvAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"refSp c5\"\n        title=\"refSp c5\"\n        src=\"/static/8df2af7ff249c2f235310c6a1dc49ae8/fcda8/refSp_c5.png\"\n        srcset=\"/static/8df2af7ff249c2f235310c6a1dc49ae8/12f09/refSp_c5.png 148w,\n/static/8df2af7ff249c2f235310c6a1dc49ae8/e4a3f/refSp_c5.png 295w,\n/static/8df2af7ff249c2f235310c6a1dc49ae8/fcda8/refSp_c5.png 590w,\n/static/8df2af7ff249c2f235310c6a1dc49ae8/efc66/refSp_c5.png 885w,\n/static/8df2af7ff249c2f235310c6a1dc49ae8/c83ae/refSp_c5.png 1180w,\n/static/8df2af7ff249c2f235310c6a1dc49ae8/1e1c3/refSp_c5.png 1670w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></a></p>\n<h4>Commit 6 : Move the instantation of the FileStream to where it is needed</h4>\n<p>Here I limit the scope of the <strong>using</strong> block to what is necessary. I think I could have used Resharper but some times you can just eyeball things. Yes, that's OK. The commit is small enough to be able to look back and think \"Yeah, that was fine\" .</p>\n<p><a href=\"../images/refSp_c6.png\"><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 16.89189189189189%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAADCAYAAACTWi8uAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAm0lEQVQI1x2O2Q7DMAgE8//f2RxKfMZgjJ12S/wwQuxKA4sw49c7GhHSeU5u58ApocYIyRlDFdIE4ztsVrAwuBJabxjPmPnk6VjERI/RS8FtsrjvCEY6DrD30FcogqYNOhRqkpgjXHDwRkgBVAtE6+wWFbvS2vyimrTYZ3eKIBN1Ez2Wvx0JQQYbFS6f2K4PVmO7VtsvhOLBSvgD7AXnG8Vfm+wAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"refSp c6\"\n        title=\"refSp c6\"\n        src=\"/static/57b08120c55e47f01e809d8f160c820b/fcda8/refSp_c6.png\"\n        srcset=\"/static/57b08120c55e47f01e809d8f160c820b/12f09/refSp_c6.png 148w,\n/static/57b08120c55e47f01e809d8f160c820b/e4a3f/refSp_c6.png 295w,\n/static/57b08120c55e47f01e809d8f160c820b/fcda8/refSp_c6.png 590w,\n/static/57b08120c55e47f01e809d8f160c820b/efc66/refSp_c6.png 885w,\n/static/57b08120c55e47f01e809d8f160c820b/c83ae/refSp_c6.png 1180w,\n/static/57b08120c55e47f01e809d8f160c820b/4352a/refSp_c6.png 1364w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></a></p>\n<h4>Commit 7 : Extract CreateFile into a new class; extract interface and use this in the code. DownloadFile has 4 params but we can live with that for the moment</h4>\n<p>Moving a bit quicker in this commit. I extract a new method, CreateFileFromSharepointClientResult, and then extract that into a new class, FileCreator, and then extract an interface for it, IFileCreator.</p>\n<p><a href=\"../images/refSp_c7p0.png\"><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 48.64864864864865%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAA7DAAAOwwHHb6hkAAABf0lEQVQoz3WS2XLCMAxF8/+/x/SNFkpYgrN6je0st5IgDH3AM2cUyfaN5etiTglD06JTCnYYBKe1YPoeQRvknBDziK5v0XYNjDMw1jwi0esO1tN6oliXBQsxhgBnLayxCN5jyhnzPINHpu9lXSR33sGSmDYaYQyYJl43YRtFbBqkukZ/POL69YXzbod6v4cpS4SqAs9H+pkfPQl41K3CTV1RqRvqTsnptB3gg5M1ckKGT5RiRCY4x7riNTdNnMpYZjrpNFNXK/6NVbag4DaY5dk6s9UEyhPds4/Uquf76uU+4xQf8UmiPM8JReB26M4+wfOO2rl0J/yqA47VN071Ade+lNpGNVxQu+ohuPFJkO/nNpxxUj8ieLjtRbSsj1Kv9EUQQd5k2V1iE3hnHEdy1uKuyQjafO1KEeHNjb+jDeoF5wU/CeecCLJAJFNGQiKJcYwpkoOO3pwWxPHoJXL9EbkWyGWyhkV583YiNobrGzy/kqs5Pdf5QC8iiavv65g/wZUEKPud340AAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"refSp c7p0\"\n        title=\"refSp c7p0\"\n        src=\"/static/f2918be62b34985a40299ea2610ed14e/fcda8/refSp_c7p0.png\"\n        srcset=\"/static/f2918be62b34985a40299ea2610ed14e/12f09/refSp_c7p0.png 148w,\n/static/f2918be62b34985a40299ea2610ed14e/e4a3f/refSp_c7p0.png 295w,\n/static/f2918be62b34985a40299ea2610ed14e/fcda8/refSp_c7p0.png 590w,\n/static/f2918be62b34985a40299ea2610ed14e/efc66/refSp_c7p0.png 885w,\n/static/f2918be62b34985a40299ea2610ed14e/c83ae/refSp_c7p0.png 1180w,\n/static/f2918be62b34985a40299ea2610ed14e/2a077/refSp_c7p0.png 1533w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></a></p>\n<p>In the calling method, create a FileCreator, which DownloadFile will accept as an IFileCreator. We can move these instantiations up the chain later but for just now this is fine and keeps the commits simple.</p>\n<p><a href=\"../images/refSp_c7p1.png\"><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 25.675675675675674%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAFCAYAAABFA8wzAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAA1klEQVQY00VQ2XZEIQzy/z+1veOucYsU7Uz7wEENIUTTakXyHsFa5BDQSkHN6bKOgT0nFjF4zjkjxohAnYj8YbKuW6GqMLoWhM2FYqH54ZrLPTep1+xojviYFtaaNNYFlZpf03ZNsQHzaTjTvXNITJBSgmPiQtb1TjgHlk5UKXjZB9a/4KOH85bsIJ1J14CZrWH1flNmmh3unHrWFw45ay9COhMvvkvC477w+G+EzK/KgXCIlfpZYfbeN26n6fjwmG8MtHvnX+pmWq7dB/ULk/WL+a89vT+OQYU8RTOTUAAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"refSp c7p1\"\n        title=\"refSp c7p1\"\n        src=\"/static/809f54d3dfd1ba3bfb02b19e33e046f2/fcda8/refSp_c7p1.png\"\n        srcset=\"/static/809f54d3dfd1ba3bfb02b19e33e046f2/12f09/refSp_c7p1.png 148w,\n/static/809f54d3dfd1ba3bfb02b19e33e046f2/e4a3f/refSp_c7p1.png 295w,\n/static/809f54d3dfd1ba3bfb02b19e33e046f2/fcda8/refSp_c7p1.png 590w,\n/static/809f54d3dfd1ba3bfb02b19e33e046f2/efc66/refSp_c7p1.png 885w,\n/static/809f54d3dfd1ba3bfb02b19e33e046f2/c83ae/refSp_c7p1.png 1180w,\n/static/809f54d3dfd1ba3bfb02b19e33e046f2/01294/refSp_c7p1.png 1615w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></a></p>\n<h4>Commit 8 : Extracted ISharepointFile which is used in a call to IClientContext but there is still a dependency on ClientContext which we cannot instantiate in the tests. Hmm</h4>\n<p>Similar to commit 7, I extracted an interface for a new adapter around the Sharepoint File object.</p>\n<p><a href=\"../images/refSp_c8p0.png\"><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 35.13513513513513%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAHCAYAAAAIy204AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAA80lEQVQoz5WQ2W7DIBBF/f//mMaO48Q2AWN2s90CSqP0JWofjmZGdzgCuugcdkrBCIHkHIrvBd56IyWc1nDG4PBlT3IQSlr9YRMMSksYp2GsQZdDRChSJQR0oQqi940UAnIseekPf8BHD6kkhNzBBUeIASEFxELKsc1dSgk5Z9SayuFKnRvPLFZpqIdS69vuM3unZp0rt7PWotZPbJJiIheMy4CZTdgMBbfsF8JydKb8jy7P/IQ1FmRf0C8nDOsXrnTAbRuxqjuImhu1p5r8XUglacJ+PmEkPe58wkMvL6qU6cf/hFc24LKei/CMRdxeonfhN7uyG5raGPCJAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"refSp c8p0\"\n        title=\"refSp c8p0\"\n        src=\"/static/74d166907f46dc94e94213374de2ed9d/fcda8/refSp_c8p0.png\"\n        srcset=\"/static/74d166907f46dc94e94213374de2ed9d/12f09/refSp_c8p0.png 148w,\n/static/74d166907f46dc94e94213374de2ed9d/e4a3f/refSp_c8p0.png 295w,\n/static/74d166907f46dc94e94213374de2ed9d/fcda8/refSp_c8p0.png 590w,\n/static/74d166907f46dc94e94213374de2ed9d/efc66/refSp_c8p0.png 885w,\n/static/74d166907f46dc94e94213374de2ed9d/c83ae/refSp_c8p0.png 1180w,\n/static/74d166907f46dc94e94213374de2ed9d/d8c86/refSp_c8p0.png 1663w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></a></p>\n<p>In the calling method, create a SharepointFileAdapter, as DownloadFile will accept as an ISharepointFile now.</p>\n<p><a href=\"../images/refSp_c8p1.png\"><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 7.4324324324324325%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAABCAYAAADeko4lAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAATElEQVQI1xXKSRKAIAwAQf//RxcEUQwuB6tMcBnLPnd1qfKWwp4XgnOkIZLnmcl7VhHO4+A/txpmil1KeYxRIm1f0/mGmAbC6Mmb8AEIpUu76fcdaAAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"refSp c8p1\"\n        title=\"refSp c8p1\"\n        src=\"/static/fa4be9acfd8eddb68c069ae48294b204/fcda8/refSp_c8p1.png\"\n        srcset=\"/static/fa4be9acfd8eddb68c069ae48294b204/12f09/refSp_c8p1.png 148w,\n/static/fa4be9acfd8eddb68c069ae48294b204/e4a3f/refSp_c8p1.png 295w,\n/static/fa4be9acfd8eddb68c069ae48294b204/fcda8/refSp_c8p1.png 590w,\n/static/fa4be9acfd8eddb68c069ae48294b204/efc66/refSp_c8p1.png 885w,\n/static/fa4be9acfd8eddb68c069ae48294b204/c83ae/refSp_c8p1.png 1180w,\n/static/fa4be9acfd8eddb68c069ae48294b204/bed7a/refSp_c8p1.png 1437w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></a></p>\n<h4>Commit 9 : Updated the wrapper to use its stored ClientContext so that the interface can lose its dependency on the Sharepoint ClientObject type in favour of an ISharepointFile which can be mocked</h4>\n<p>IClientContext now loads a ISharepointFile, breaking the dependency on a Sharepoint ClientObject.</p>\n<p><a href=\"../images/refSp_c9p0.png\"><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 27.7027027027027%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAYAAADDl76dAAAACXBIWXMAAA7DAAAOwwHHb6hkAAABA0lEQVQY02WQi2rEIBBF8/8fWAqFstuWhN3EmKjjW29HbUOh4uGKzus6ye3Avj5htYUzmiE+s2ozlO+iczDW4LFv+FjuWMQXTDhh/ED7Y6g7MB1S45A7tNIgMkgpouTEZOSuCZnvnLNQ3HQTK+Qh+HzCB4tc4kViJikNBAcJITjJIcaAWitTLi0lI0UuSoWbn5Bih9GEGCJqqQDvXyYyFlorKKVYqU/ifezFvQ+M65BlJzzVc3/isc1Y5QapBbTlXHteTETUrY5C7h8heKizFVpwW294m1+ZF3zu75jVvbP8aGOyFDiBP7V9Ptv9O3+z21Zr2FykWDmOemxzUMt4H/FjfQPwXs+8fFUFBwAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"refSp c9p0\"\n        title=\"refSp c9p0\"\n        src=\"/static/0eeb0a60d6889d958a7bd1e820b409be/fcda8/refSp_c9p0.png\"\n        srcset=\"/static/0eeb0a60d6889d958a7bd1e820b409be/12f09/refSp_c9p0.png 148w,\n/static/0eeb0a60d6889d958a7bd1e820b409be/e4a3f/refSp_c9p0.png 295w,\n/static/0eeb0a60d6889d958a7bd1e820b409be/fcda8/refSp_c9p0.png 590w,\n/static/0eeb0a60d6889d958a7bd1e820b409be/efc66/refSp_c9p0.png 885w,\n/static/0eeb0a60d6889d958a7bd1e820b409be/c83ae/refSp_c9p0.png 1180w,\n/static/0eeb0a60d6889d958a7bd1e820b409be/a5a94/refSp_c9p0.png 1657w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></a></p>\n<p>In DownloadFile I can now pass in the ISharepointFile, tidying this up.</p>\n<p><a href=\"../images/refSp_c9p1.png\"><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 10.135135135135135%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAACCAYAAABYBvyLAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAaklEQVQI11XMSRLDIAxEUd//qHYMxqARhY7iyiaLV1roV29zBq5KqLWAaGCM/uj9hrDCTKEqYB5wD7RLUMoJYvpr+ddukbEMwp2D9djRXgciH1/vtNywpsOEoZ7DyqitPEg6PCwpZt5Yjg/xWZr7hAffAQAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"refSp c9p1\"\n        title=\"refSp c9p1\"\n        src=\"/static/d3f05c05ec4b6f454f28cd93877976bf/fcda8/refSp_c9p1.png\"\n        srcset=\"/static/d3f05c05ec4b6f454f28cd93877976bf/12f09/refSp_c9p1.png 148w,\n/static/d3f05c05ec4b6f454f28cd93877976bf/e4a3f/refSp_c9p1.png 295w,\n/static/d3f05c05ec4b6f454f28cd93877976bf/fcda8/refSp_c9p1.png 590w,\n/static/d3f05c05ec4b6f454f28cd93877976bf/efc66/refSp_c9p1.png 885w,\n/static/d3f05c05ec4b6f454f28cd93877976bf/c83ae/refSp_c9p1.png 1180w,\n/static/d3f05c05ec4b6f454f28cd93877976bf/087e3/refSp_c9p1.png 1575w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></a></p>\n<h4>Commit 10 : Quick tidyup</h4>\n<p><a href=\"../images/refSp_c10.png\"><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 23.64864864864865%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAFCAYAAABFA8wzAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAw0lEQVQY031Qy24DIRDj/3+ze0iUkOUNCzO4hrSnKkWyPBqEbWyu1pBi3MgpQfogOmSMv+BeRdCvC51zrRWlFOScMYZgzglTY8DtOHD7OmDvd1QKlxDJ6QfvudGshIBBkS1IA+8c7PMJdzpc3KkqjE5AqSwEx+3y31m3gyknHwr5Fyq6d6Yzrl8u1uJ8PJCdhzDFR7CiRm6jISSPl3/BnhYxB7ReYVY3hd9Z/RWKr9gr5Vz8Aet7osIO3/3FFFlB3/m/AYuqhpNkrHy7AAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"refSp c10\"\n        title=\"refSp c10\"\n        src=\"/static/8a7b16f2d7502128c826d397dc34b92d/fcda8/refSp_c10.png\"\n        srcset=\"/static/8a7b16f2d7502128c826d397dc34b92d/12f09/refSp_c10.png 148w,\n/static/8a7b16f2d7502128c826d397dc34b92d/e4a3f/refSp_c10.png 295w,\n/static/8a7b16f2d7502128c826d397dc34b92d/fcda8/refSp_c10.png 590w,\n/static/8a7b16f2d7502128c826d397dc34b92d/efc66/refSp_c10.png 885w,\n/static/8a7b16f2d7502128c826d397dc34b92d/c83ae/refSp_c10.png 1180w,\n/static/8a7b16f2d7502128c826d397dc34b92d/afa26/refSp_c10.png 1258w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></a></p>\n<p>Now, finally, with the removal of the Load method from IClientContext, I have removed the dependencies on the Sharepoint types, in favour of interfaces.</p>\n<p>So, at last, I can write some tests to protect this code.</p>\n<h4>Commit 11 : Added tests for DownloadFile and its collaborators</h4>\n<p>Firstly a test for the happy path, when Sharepoint is playing nicely.</p>\n<p><a href=\"../images/refSp_c11p0.png\"><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 46.621621621621614%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAA7DAAAOwwHHb6hkAAABjklEQVQoz32S2XLCMAxF+f/f6fShQ4GQrUlI7NixwxKaQmmh+y/cSgpl+tI+3JEta6QjySP3pKF6jfbo0DyV8M8KjmxzlqN7e1SwhxL2cSG+zXuD7sNd7G+NlidDgR7VtkCxDlF2McyuRrnNsNjEKDYRnVMptHypRf8m7D4sdG8xq24QqCnm9QSxSxDZALfFNVIfYNElQtietIgT/aXR5t2ifjCYqTHiZoLKz1G6GBWRFUSr+jv4I9NpoWT9Jtp+enSfZ8uE6zcr81N9huagUPclKkpU3SdQDwXMXot0byQxx69ezKV9Jl6eBsv+EWOW1NJNdoVxfo3ITJC2AfJVhECPkbgZtT9FaKZImikVSmm2Ee7aObJliIxsvgqp6ELohbCh+fDweQlmn9MmK6muqV29y8lXwNJ2azozxdDeeSF05vv9F1s3EHJgRNVjUupnMrtymwhR4gYfLyc0t/QbEgLQsHtPhYcvxeNyBCEzXL0a2U571ELK4kehpNl48vOd2+G3n/j1m7tslrv8+ULf4Pd00p80WA0AAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"refSp c11p0\"\n        title=\"refSp c11p0\"\n        src=\"/static/e8cdfe4341b560199f9011247ffdb5af/fcda8/refSp_c11p0.png\"\n        srcset=\"/static/e8cdfe4341b560199f9011247ffdb5af/12f09/refSp_c11p0.png 148w,\n/static/e8cdfe4341b560199f9011247ffdb5af/e4a3f/refSp_c11p0.png 295w,\n/static/e8cdfe4341b560199f9011247ffdb5af/fcda8/refSp_c11p0.png 590w,\n/static/e8cdfe4341b560199f9011247ffdb5af/0098c/refSp_c11p0.png 775w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></a></p>\n<p>Experience has shown us that it can return a 503 so there is a retry mechanism in place. Now I test the case when a 503 is thrown in the first Sharepoint call.</p>\n<p><a href=\"../images/refSp_c11p1.png\"><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 67.56756756756756%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAYAAAAvxDzwAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAB5ElEQVQ4y4VT2XLbMBDT/39T6kvURVE3JUu03cSp49z5hS125SgzrpI+YJbkDEEQi/VUe0PuzdL+vRUcPhidrHc4373br3pZu9dmPJuBZ/YZpU6RcQGZfUjpLpB9eZdQ88dMqO9Tqf1z9SMpCBOQxJT0CtiQBln3WNDwUsul4QWQWk9nPxImfUiBXVDYrkHIKiM8EFF2iMiyoodsxMnQ8FT+/8tMwoSBXVJxG1N1TFETEIbjHl8vse9B5qBWyF6b7xXaU47LMRl4V91reDX6ZR9ysqdMfOP15wUmct+oE8LmVFF5rKm4Sym/1aKMCdmvz85PRDO4tsBb5Ip+5T6pyqe4U7Spb6QxFauEwu6xnIivMeenF/cxGrIg060pQ3Ry+Db6FyE6sfjIEWJURy3gNf9iVmHGsXEhJUMAcGwC0kNE0TbBPpQG5b/jCYXUiNqLr+6qQV5gV/jmklTN0VmSj6oaVKtI76HmaCjFo3qnJU7cdbZhJPjXUy9oFS77ULSR70XblURIO1+CzqqVXVPYbSjqVjJJ01jOdTk7YNR2SsBfyQ6JRIgbo0FoQJzCAoNpSi/nWyjkXG6fuFZTFYXducBBJWix7s4tDc+1jF8POFx2PIq4xGftOafmks8G0/OV1UzG9C91PtePs69RygAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"refSp c11p1\"\n        title=\"refSp c11p1\"\n        src=\"/static/1733645ca1cbdb8e06a78deb5a72fee0/fcda8/refSp_c11p1.png\"\n        srcset=\"/static/1733645ca1cbdb8e06a78deb5a72fee0/12f09/refSp_c11p1.png 148w,\n/static/1733645ca1cbdb8e06a78deb5a72fee0/e4a3f/refSp_c11p1.png 295w,\n/static/1733645ca1cbdb8e06a78deb5a72fee0/fcda8/refSp_c11p1.png 590w,\n/static/1733645ca1cbdb8e06a78deb5a72fee0/efc66/refSp_c11p1.png 885w,\n/static/1733645ca1cbdb8e06a78deb5a72fee0/ee9b6/refSp_c11p1.png 1041w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></a></p>\n<p>Which uses these helper methods:</p>\n<p><a href=\"../images/refSp_c11p2.png\"><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 27.7027027027027%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAYAAADDl76dAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAA4klEQVQY032Qy5aCMBBE+f9/mnEhICZIEkDkjTKz8IW/UFZwomcWurinupPuOql4qi+h+oIkkI2PdbmErH3WAUTlI+F53IbYdCvW0YwaqGTThdB7geqcornmqC8ZvPw3gz4ImEMEM0qkP/EL9mYUKI4KzZShuxVob9tZHbZ3Zla96mxQngzaiZdTPh/+57FgX/EOZza/UA8lzL6AHh7RZB08I9pISR8zlqSuOLNm/QdTKaqNvzvql2E65jSIEGRfWGbf8EmQLxBuF1T2rAX/1iaxC+94GtYXg91JfRx2C59wM3eQ5adlW3XqmAAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"refSp c11p2\"\n        title=\"refSp c11p2\"\n        src=\"/static/67d72b826eded9a27c777e10d6aee47f/fcda8/refSp_c11p2.png\"\n        srcset=\"/static/67d72b826eded9a27c777e10d6aee47f/12f09/refSp_c11p2.png 148w,\n/static/67d72b826eded9a27c777e10d6aee47f/e4a3f/refSp_c11p2.png 295w,\n/static/67d72b826eded9a27c777e10d6aee47f/fcda8/refSp_c11p2.png 590w,\n/static/67d72b826eded9a27c777e10d6aee47f/73fd0/refSp_c11p2.png 793w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></a></p>\n<p>Now I test the case when a 503 is thrown in the second Sharepoint call.</p>\n<p><a href=\"../images/refSp_c11p3.png\"><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 590px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 68.24324324324324%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAYAAAAvxDzwAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAB9klEQVQ4y3VTWXbiQAz0/a+Ux+59xe0FG0xIhgCZZJIr1JSEWULgQ0+i21SXVCUraCfw2zG67wrr7xrdl+RL/ShWXyVW/0osPwvNp7DmLwbRMkS0shGvHCRrj7XDMxvz1xDFNtYwV9lsI5RvyRnsGtQqdwZJ5xPMh7+YIWimiDsHi/c52g9zjuaU/0rkaJnvAlb7giA2nHIEt5qyJruVxwc8ZC8Bql2Cdp+iPWRo3mK07/m53bstV7tcmTnlkIBjzAmSbQKkz74Cyu9aAJVVjiVZLnuguwzbT8OZpDq7pHNRkIX5E2kUnNNpbuUufcjqB8MFW8g2MecWwW9mZMtZNp4CyR9V0StGt3EEutSW2RoM4gGGyRDTlHMsbYyzJ4RUOSdLYSYCia3u2efXDOt9SSFcePUIKcVJ2Xa68ZE8e8hfA7YeMocKrmM42UcfS36wPwIeSlU0aN1jy82E7FxV26s91o6Cy4zT9SWLZ2XGvwClJbsYYmZGsM0ATjVizVyOYVc0Oz0q7OKOhle/usq4PszVPrczteQVp5oQgCtIU2ds1yWoAMv2BO1MQ+69eqrfhMvZY5VrGlY2Q0SQlUvZnrCSWs5CAkQECBtPtynqv2voDtmY27DkouqVrPeZqlrvKyz680ZM3UdzON7LedHvtPj2JJTs93/jbtZOSI23jAAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"refSp c11p3\"\n        title=\"refSp c11p3\"\n        src=\"/static/287ad63b6c44014c1677adc97cf302cc/fcda8/refSp_c11p3.png\"\n        srcset=\"/static/287ad63b6c44014c1677adc97cf302cc/12f09/refSp_c11p3.png 148w,\n/static/287ad63b6c44014c1677adc97cf302cc/e4a3f/refSp_c11p3.png 295w,\n/static/287ad63b6c44014c1677adc97cf302cc/fcda8/refSp_c11p3.png 590w,\n/static/287ad63b6c44014c1677adc97cf302cc/efc66/refSp_c11p3.png 885w,\n/static/287ad63b6c44014c1677adc97cf302cc/35a31/refSp_c11p3.png 1028w\"\n        sizes=\"(max-width: 590px) 100vw, 590px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></a></p>\n<h4>Tests, at last</h4>\n<p>There are a few more commits (which I've omitted here as I think that this is long enough already) where the code is tidied up further, now that I have the security of the unit tests in place: renamed, reduce the number of parms to a method, move the classes &#x26; interfaces into their own files.</p>\n<p>The code is not yet perfect as you can see by the complexity of the unit tests: there is still a lot going on, but that's a matter for another day.</p>\n<p>I hope that this gives somebody a helpful view point of taking some slightly messy code whic some awkward dependencies and shows how it can be refactored safely (almost entirely using Resharper to refactor) into a state where it can be protected by unit tests.</p>","frontmatter":{"date":"April 24, 2019","slug":"/blog/refactoring-legacy-code-a-case-study","title":"Refactoring legacy code: a case study."}}},"pageContext":{"slug":"/blog/refactoring-legacy-code-a-case-study"}},"staticQueryHashes":["3649515864"]}